import Foundation

protocol DWJsonUrlValue {}
extension NSURL: DWJsonUrlValue {}
extension URL: DWJsonUrlValue {}

func dw_url(_ value: Any) -> DWJsonUrlValue? {
    guard let str = value as? String, str.contains("://")
        else { return value as? URL }
    return str.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed).flatMap { URL(string: $0) }
}
